const lark = require("@larksuiteoapi/node-sdk");
var axios = require("axios");


//更改对应的app_id
const FEISHU_APP_ID = "cli_a5353776bba9100d";
const FEISHU_APP_SECRET = "nSNp3X7T6NWgP7kkY3Rt9dGJpfjBbPcR";


const client = new lark.Client({
    appId: FEISHU_APP_ID,
    appSecret: FEISHU_APP_SECRET,
    disableTokenCache: false,
    appType: lark.AppType.SelfBuild,
    domain: lark.Domain.Feishu,
});


// 回复文本消息
async function reply(messageId, content) {
    console.log("reply", messageId + " " + content);
    try {
        return await client.im.message.reply({
            path: {
                message_id: messageId,
            },
            data: {
                content: JSON.stringify({
                    text: content,
                }),
                msg_type: "text",
            },
        });
    } catch (e) {
        console.log("send message to feishu error", e, messageId, content);
    }
}

async function replyCard(messageId, content) {
    console.log("reply", messageId + " " + content);
    try {
        return await client.im.message.reply({
            path: {
                message_id: messageId,
            },
            data: {
                content: lark.messageCard.defaultCard({
                    title: 'Card Title',
                    content: 'Card Content'
                }),
                msg_type: "interactive",
            },
        });
    } catch (e) {
        console.log("send message to feishu error", e, messageId, content);
    }
}

console.log("回复消息-start");

async function executeAsyncFunction001() {
    try {
        //const result = await reply("om_3066a55cff402d0772511a53410f10c7", "我是reply消息")
        const result = await replyCard("om_3066a55cff402d0772511a53410f10c7", "我是reply消息")
        console.log(result); // 输出 'Hello World'
    } catch (error) {
        console.error(error);
    }
}

executeAsyncFunction001()
console.log("回复消息-end");
